package project.layer.physical.commands;

import project.layer.physical.Truck;
import framework.layer.physical.command.Command;
import framework.layer.physical.command.CommandUncompletedException;
import framework.layer.physical.command.IllegalCommandException;
import framework.layer.physical.connections.Connector.CannotEnterOnroadException;
import framework.layer.physical.connections.Connector.IllegalEnterException;

public class EnterCrossroadCommand extends Command<Truck> {

	public EnterCrossroadCommand(Truck truck) {
		super(truck);
	}

	@Override
	public void execute() throws IllegalCommandException,
			CommandUncompletedException {
		if(getEntity().isOnConnection()){
			try {
				getEntity().getConnectionPosition().getConnection().getConnectorAtEnd(getEntity().getConnectionPosition().getDirection()).enterOnroad(getEntity());
			} catch (CannotEnterOnroadException e) {
				e.printStackTrace();
			} catch (IllegalEnterException e) {
				e.printStackTrace();
			}
		}
	}

}
